package com.qi.demo01.Singleton;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author zjq
 * @date 2020/3/30 20:39
 */
public enum Enumsingle {
    //枚举是一个什么东西？本身也是一个class类

    INSTANCE;

    public Enumsingle getInstance() {
        return INSTANCE;
    }
}

class Test {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Enumsingle enumsingle = Enumsingle.INSTANCE;

//        Enumsingle enumsingle1 = Enumsingle.INSTANCE;
//        System.out.println(enumsingle.hashCode());
//        System.out.println(enumsingle1.hashCode());
        Constructor<Enumsingle> declaredConstructor = Enumsingle.class.getDeclaredConstructor(String.class, int.class);
        declaredConstructor.setAccessible(true);
        Enumsingle enumsingle1 = declaredConstructor.newInstance();


        // java.lang.NoSuchMethodException: com.qi.demo01.Singleton.Enumsingle.<init>()
        System.out.println(enumsingle);
        System.out.println(enumsingle1);
    }
}